import axios from 'axios'
import Cookies from 'js-cookie'
import Vue from 'vue'
const requset = axios.create({
  baseURL: '/api',
  timeout: 5000
})

requset.interceptors.request.use(function (config) {
  Vue.$loading.show()
  const token = Cookies.get('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config
}, function (error) {
  return Promise.reject(error)
})

requset.interceptors.response.use(function (response) {
  Vue.$loading.hide()
  return response
}, function (error) {
  return Promise.reject(error)
})
export default requset
